﻿@using NewLife.Common;
@using XCode.Membership;
@{
    var user = ViewBag.User as IUser ?? User.Identity as IUser;
    var uid = 0;
    var roleNames = "";
    if (user != null)
    {
        uid = user.ID;
        roleNames = user.Roles == null ? "" : user.Roles.Join();
    }
    var cfg = ViewBag.Config as SysConfig;
    var name = cfg == null ? "" : cfg.DisplayName;

    var set = CubeSetting.Current;
}
<!-- #section:basics/navbar.layout -->
<div id="navbar" class="navbar navbar-default">
    <script type="text/javascript">
        try { ace.settings.check('navbar', 'fixed') } catch (e) { }
    </script>

    <div class="navbar-container" id="navbar-container">
        <!-- #section:basics/sidebar.mobile.toggle -->
        <button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler" data-target="#sidebar">
            <span class="sr-only">Toggle sidebar</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>

        <!-- /section:basics/sidebar.mobile.toggle -->
        <div class="pull-left">
            <!-- #section:basics/navbar.layout.brand -->
            <a href="@ViewBag.Main" class="navbar-brand" target="main">
                <small>
                    @name
                </small>
            </a>
        </div>

        <!-- #section:basics/navbar.dropdown -->
        <div class="navbar-buttons navbar-header pull-right" role="navigation">
            <ul class="nav ace-nav">
                <!-- #section:basics/navbar.user_menu -->
                <li class="light-blue">
                    <a data-toggle="dropdown" href="~/Admin/User/Info" class="dropdown-toggle" target="main">
                        @if (user != null && !user.Avatar.IsNullOrEmpty())
                        {
                            <img class="nav-user-photo hidden-xs" src="@user.GetAvatarUrl()" alt="@user" />
                        }
                        <span class="user-info hidden-xs">
                            @user<br />
                        </span>

                        <i class="ace-icon fa fa-caret-down"></i>
                    </a>

                    <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-caret">
                        <li>
                            <a href="~/" target="_blank">
                                <i class="ace-icon fa fa-cog"></i>
                                系统首页
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="~/Admin/User/Info/@uid" target="main">
                                <i class="ace-icon fa fa-user"></i>
                                个人信息
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="~/Admin/User/Logout">
                                <i class="ace-icon fa fa-power-off"></i>
                                注销
                            </a>
                        </li>
                    </ul>
                </li>
                <!-- /section:basics/navbar.user_menu -->
            </ul>
        </div>

        <!--tenant-->
        @if (set.EnableTenant && user != null)
        {
            var tList = TenantUser.FindAllByUserId(user.ID);

            var tenant = XCode.Membership.Tenant.FindById(TenantContext.CurrentId);
            var tenantName = tenant?.Name;

            <div class="navbar-buttons navbar-header pull-right" role="navigation">
                <ul class="nav ace-nav">
                    <li class="light-blue">
                        <a data-toggle="dropdown" href="#" class="dropdown-toggle" target="main">
                            <span class="hidden-xs" title="租户模式禁止访问系统管理，平台管理模式禁止访问租户页面" style="line-height:45px;top:0px;">
                                @(tenantName ?? "系统后台")
                            </span>
                            <i class="ace-icon fa fa-caret-down"></i>
                        </a>

                        <ul class="dropdown-menu-right dropdown-menu dropdown-caret">
                            @if (user.Roles.Any(e => e.IsSystem))
                            {
                                <li>
                                    <a href="~/Admin/Index?tenantid=0">
                                        <span class="hidden-xs" title="系统管理后台，用于管理租户，但不能访问租户页面" style="line-height:45px;top:0px;">
                                            系统管理后台
                                        </span>
                                    </a>
                                </li>
                                <li class="divider"></li>
                            }

                            @foreach (var item in tList)
                            {
                                <li>
                                    <a href="~/Admin/Index?tenantid=@item.TenantId">
                                        <i class="ace-icon fa fa-cog"></i>
                                        @item.TenantName
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                </ul>
            </div>
        }
        <!-- /section:basics/navbar.dropdown -->
    </div>
    <!-- /.navbar-container -->
</div>
<!-- /section:basics/navbar.layout -->